package com.zyk.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zyk.entity.Role;
import com.zyk.entity.RoleResource;
import com.zyk.mapper.RoleResourceMapper;
import com.zyk.service.IRoleResourceService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zyk.vo.FinalResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色资源 服务实现类
 * </p>
 *
 * @author feifeimao
 * @since 2017-11-20
 */
@Service
public class RoleResourceServiceImpl extends ServiceImpl<RoleResourceMapper, RoleResource> implements IRoleResourceService {

    @Autowired
    private RoleResourceMapper roleResourceMapper;


    /**
     * 角色授权
     *
     * @param id
     * @param resourceIds
     * @return
     */
    public FinalResult grant(Long id, Long[] resourceIds) {
        //先删除所有相关的记录
        RoleResource roleResource = new RoleResource();
        roleResource.setRoleId(id);
        for (Long ids : resourceIds) {
            roleResourceMapper.insert(new RoleResource(id, ids));
        }
        return new FinalResult("授权成功", true);
    }
}
